//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "adminActions\fn_kick.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_params","_caller_name","_caller_uid","_player_uid","_player_name","_player_info","_action","_authorized","_player","_player_id","_counter","_player_pos"];
PARAMS_3(_params,_caller_name,_caller_uid);

_authorized = _params select 0;
_action = _params select 1;
_player = _params select 2;
_player_uid = _params select 3;
_player_name = _params select 4;

if (isServer) then {
	if (!isnil "mp_rights_fnc_isMember" && {_player call mp_rights_fnc_isMember}) exitWith {ERROR_1("You cannot punish a member",_this);};
	_player_info = [];
	_index = GVAR(PlayerIndex) find _player_uid;
	if (_index >= 0) then {
		_player_info = GVAR(PlayerInfo) select _index;
	};
	TLOG_1("KICK",ARR_2((serverCommandAvailable "#kick"),_player_info));
	serverCommand "#login TOMI";
	if (count _player_info > 0) then {
		// _player_info set [0, _name];	// Player name at login
		// _player_info set [1, _uid];		// Player UID
		// _player_info set [2, _id];		// Player DirectPlay ID at login
		// _player_info set [3, MSO_AA_PLAYER_ID_COUNT]; // Player ID at login
		// _player_info set [4, time];		// Player first login time
		// _player_info set [5, getPos player];// Initial Position
		// _player_info set [6, time];		// Player last login time
		// _player_info set [7, 0];		// Player jails
		// _player_info set [8, 0];		// Player kicks
		// _player_info set [9, 0];		// Player bans
		// _player_info set [10, 0];		// Player teleports
		// _player_info set [11, 0];		// Player vehicle crashes
		
		_player_id = (_player_info select 3);
		_player_name = (_player_info select 0);
		_player_pos = (_player_info select 5);
		
		// Increment the counter of the actions performed against the user
		_counter = (_player_info select 8) + 1;
		_player_info set [8, _counter];
		GVAR(PlayerInfo) set [_index, _player_info];
		
		TLOG_1("Kick command id",_command);
		_player_id = str(_player_id);
		serverCommand ("#kick " + _player_id);
	} else {
		ERROR_1("Missing Player Info",_player_uid);
	};
	serverCommand ("#kick " + _player_name);
	serverCommand ("#kick " + _player_uid);
};
if (!isDedicated) then {
	if (_player_uid == getPlayerUID player) then {
		if (!isnil "mp_rights_fnc_isMember" && {player call mp_rights_fnc_isMember}) exitWith {};
		// Temporary fix for the F***ing serverCommand not working.
		endMission "LOSER";
	} else {
		hint format[localize "STR_MSO_AA_KICKED", _player_name, _player_uid];
	};
};

TRACE("End");
TMFPROFILERSTOP;
